<?php

/**
 * reservacion actions.
 *
 * @package    blackDrums
 * @subpackage reservacion
 * @author     your name here
 */
class reservacionActions extends sfActions
{
  public function executeIndex(sfWebRequest $request)
  {
    $this->Reservacions = ReservacionPeer::doSelect(new Criteria());
  }

  public function executeShow(sfWebRequest $request)
  {
    $this->Reservacion = ReservacionPeer::retrieveByPk($request->getParameter('idreservacion'));
    $this->forward404Unless($this->Reservacion); 
  }

  public function executeNew(sfWebRequest $request)
  {
    $res = new Reservacion();
    $res->setFecha($request->getParameter('dia'));
    $res->setHorainicio($request->getParameter('horaIni'));
    $this->form = new ReservacionForm($res);
  }

  public function executeCreate(sfWebRequest $request)
  {
    $this->forward404Unless($request->isMethod(sfRequest::POST));

    $this->form = new ReservacionForm();

    $this->processForm($request, $this->form);

    $this->setTemplate('new');
  }

  public function executeEdit(sfWebRequest $request)
  {
    $this->forward404Unless($Reservacion = ReservacionPeer::retrieveByPk($request->getParameter('idreservacion')), sprintf('bject Reservacion does not exist (%s).', $request->getParameter('idreservacion')));
    $this->form = new ReservacionForm($Reservacion);

  }

  public function executeUpdate(sfWebRequest $request)
  {
    $this->forward404Unless($request->isMethod(sfRequest::POST) || $request->isMethod(sfRequest::PUT));
    $this->forward404Unless($Reservacion = ReservacionPeer::retrieveByPk($request->getParameter('idreservacion')), sprintf('Object Reservacion does not exist  (%s).', $request->getParameter('idreservacion')));
    $this->form = new ReservacionForm($Reservacion);
    $reserva= ReservacionPeer::retrieveByPK($request->getParameter('idreservacion'));
    $status = $request->getParameter('status');
    $reserva->setStatus($status);

    $this->processForm($request, $this->form);

    $this->setTemplate('edit');
  }

  public function executeDelete(sfWebRequest $request)
  {

    $this->forward404Unless($Reservacion = ReservacionPeer::retrieveByPk($request->getParameter('idreservacion')), sprintf('Object Reservacion does not exist (%s).', $request->getParameter('idreservacion')));
    $Reservacion->delete();

    $this->redirect('reservacion/index');
  }

  protected function processForm(sfWebRequest $request, sfForm $form)
  {
    $form->bind($request->getParameter($form->getName()), $request->getFiles($form->getName()));
    if ($form->isValid())
    {
      $Reservacion = $form->save();

      //$this->redirect('reservacion/edit?idreservacion='.$Reservacion->getIdreservacion());
      $this->redirect('reservacion/index');
    }
  }
}
